//
//  Home_NavBar.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "Home_NavBar.h"

@interface Home_NavBar ()

@property (nonatomic, strong) UIView *searchView;
@property (nonatomic, strong) UIButton *scanBtn;
@property (nonatomic, strong) Home_navBar_MenuView *waybillBtn;
@property (nonatomic, strong) Home_navBar_MenuView *packageBtn;
@property (nonatomic, strong) Home_navBar_MenuView *storageBtn;
@property (nonatomic, strong) Home_navBar_MenuView *systemBoardBtn;

@end

@implementation Home_NavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.searchView = [[UIView alloc] initWithFrame:CGRectMake(15, 9, ScreenW - 56 - 15, 36)];
        self.searchView.backgroundColor = HexColor(0xffffff);
        self.searchView.layer.masksToBounds = YES;
        self.searchView.layer.cornerRadius = 6;
        [self addSubview:self.searchView];
        
        UIImageView *searchImgView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 6, 24, 24)];
        searchImgView.image = [UIImage imageNamed:@"icon_search"];
        [self.searchView addSubview:searchImgView];
        
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(searchImgView.nim_right + 10, 6, self.searchView.nim_width - (searchImgView.nim_right + 10), 24)];
        titleLab.textColor = HexColor(0xDBDCE6);
        titleLab.font = [UIFont systemFontOfSize:16];
        titleLab.text = @"输入单号一键搜索";
        [titleLab sizeToFit];
        titleLab.nim_centerY = searchImgView.nim_centerY;
        [self.searchView addSubview:titleLab];
        
        UIButton *searchBtn = [[UIButton alloc] initWithFrame:self.searchView.frame];
        [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:searchBtn];
        
        self.scanBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.searchView.nim_right + 10, self.searchView.nim_top, 36, 36)];
        self.scanBtn.backgroundColor = HexColorA(0xffffff, 0.2);
        self.scanBtn.layer.masksToBounds = YES;
        self.scanBtn.layer.cornerRadius = 6;
        [self.scanBtn setImage:[UIImage imageNamed:@"icon_qr"] forState:0];
        [self.scanBtn addTarget:self action:@selector(scanClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.scanBtn];
        
//        CGFloat menuW = (ScreenW - 30) * 0.25;
//        CGFloat menuH = 61;
//
//        self.waybillBtn = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(15, self.searchView.nim_bottom + 24, menuW, menuH)];
//        self.waybillBtn.iconUrl = @"icon_home_transport";
//        self.waybillBtn.titleText = @"运单查询";
//        __weak_self;
//        self.waybillBtn.clickBlock = ^{
//            if (weakself.billBlock) {
//                weakself.billBlock();
//            }
//        };
//        [self addSubview:self.waybillBtn];
//
//        self.packageBtn = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(self.waybillBtn.nim_right, self.searchView.nim_bottom + 24, menuW, menuH)];
//        self.packageBtn.iconUrl = @"icon_home_carry";
//        self.packageBtn.titleText = @"包装查询";
//        self.packageBtn.clickBlock = ^{
//            if (weakself.packageBlock) {
//                weakself.packageBlock();
//            }
//        };
//        [self addSubview:self.packageBtn];
//
//        self.storageBtn = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(self.packageBtn.nim_right, self.searchView.nim_bottom + 24, menuW, menuH)];
//        self.storageBtn.iconUrl = @"icon_home_wms";
//        self.storageBtn.titleText = @"库存查询";
//        self.storageBtn.clickBlock = ^{
//            if (weakself.storageBlock) {
//                weakself.storageBlock();
//            }
//        };
//        [self addSubview:self.storageBtn];
//
//        self.systemBoardBtn = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(self.storageBtn.nim_right, self.searchView.nim_bottom + 24, menuW, menuH)];
//        self.systemBoardBtn.iconUrl = @"icon_home_statistics";
//        self.systemBoardBtn.titleText = @"系统看板";
//        self.systemBoardBtn.clickBlock = ^{
//            if (weakself.boardBlock) {
//                weakself.boardBlock();
//            }
//        };
//        [self addSubview:self.systemBoardBtn];
    }
    return self;
}

- (void)searchClick {
    if (self.searchBlock) {
        self.searchBlock();
    }
}

- (void)scanClick {
    if (self.scanBlock) {
        self.scanBlock();
    }
}

@end

@interface Home_navBar_MenuView ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation Home_navBar_MenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) * 0.5, 0, 40, 40)];
        [self addSubview:self.iconImgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImgView.nim_bottom + 6, frame.size.width, 15)];
        self.titleLab.textColor = HexColor(0xffffff);
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLab];
        
        self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleText:(NSString *)titleText {
    _titleText = titleText;
    self.titleLab.text = titleText;
}

@end
